<?php

require('config.php');
require('constant.php');
require('common.php');

Class mall_api Extends common {

	function get_search($q,$params){
		$url=sprintf(MALL_SEARCH_YQL_BASE,$q,http_build_query($params),MALL_SEARCH_YQL_TITLE);
		$title_obj=json_decode($this->retrieve(YQL.urlencode($url)));
		$url=sprintf(MALL_SEARCH_YQL_BASE,$q,http_build_query($params),MALL_SEARCH_YQL_IMG);
		$img_obj=json_decode($this->retrieve(YQL.urlencode($url)));
		$url=sprintf(MALL_SEARCH_YQL_BASE,$q,http_build_query($params),MALL_SEARCH_YQL_PRICE);
		$price_obj=json_decode($this->retrieve(YQL.urlencode($url)));
		$img_arr = $img_obj->query->results->img;
		$price_arr = $price_obj->query->results->em;
		$search_arr=array();
		$i=0;
		foreach($title_obj->query->results->a as $obj){
			$ret=array();
			$ret['href']=$obj->href;
			$ret['title']=$obj->content;
			$ret['price']=$price_arr[$i];
			$ret['img']=$img_arr[$i]->src;
			array_push($search_arr,$ret);
			$i++;
		}
		return ($search_arr);
	}

}
?>
